package serviceimpl;

import java.util.List;

import dao.IUserDao;
import daoimpl.UserDaoImpl;
import entity.User;
import service.IUserService;

public class UserServiceImpl implements IUserService {
	int pageSize=5;
   IUserDao userDao=new UserDaoImpl();
	
	public boolean  queryUser(User user) {
		return userDao.queryUser(user);
	}
	
	public boolean addUser(User user) {
		if(!userDao.queryUser(user)) {
			return userDao.addUser(user);
		}else {
			return false;
		}
	}
	public boolean updateUserById(int id,User user) {
		 
		if(user!=null) {
			return userDao.updateUserById(id, user);
		}else {
			return false;
		}
		
	}
	public boolean deleteUserById(int id) {
		User user=userDao.queryById(id);
		if(user!=null) {
			return userDao.deleteUserById(id);
		}else {
			return false;
		}
		
	}
	
	   public User queryUserById(int id) {
		  return userDao.queryById(id);
	   }
	public List<User> queryAllUser(){
		return userDao.queryAllUser();
	}
	public List<User> queryUserByid(int id){
		return userDao.queryUserByid(id);
	}
	public int getPageCount() {
		int pageCount=0;
		int rowCount=userDao.getRowCount();
	
		
		if (rowCount % pageSize == 0) {
			pageCount = rowCount / pageSize;
		} else {
			pageCount = rowCount / pageSize + 1;
		}
		return pageCount;
	}
}
